package com.example.mylibrary.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;

/**
 * Created by qyx on 2019/4/25 15:08
 * E-Mail Address：1519682674@qq.com
 */
public abstract class FullScreenDialog extends Dialog {
    public FullScreenDialog(@NonNull Context context) {
        this(context, 0);
    }

    public FullScreenDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        setContentView(setLayout());
    }

    protected abstract int setLayout();


    @Override
    public void show() {
        if(isShowing()){
            return;
        }
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
//            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
//                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            window.setStatusBarColor(Color.TRANSPARENT);
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        }
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        layoutParams.horizontalMargin = 0;
        super.show();

    }
}
